// 释放Iframe中页面清除大部分的内存和文档节点记录数了
function clearIframe(id) {
    var el = document.getElementById(id), iframe = el.contentWindow;
    if (el) {
        el.src = 'about:blank';
        try {
            iframe.document.write('');
            iframe.document.clear();
        } catch (e) {
        }
    }
}

$(function () {

    //设置iframe的高度
    //setIframeHeight('frameContext');

    //获取天气信息
    findWeather();


    //浏览器改变大小事件，为了解决iframe内容自适应的问题
    window.onresize = function () {
        var iframe = document.getElementById('frameContext');

        //调用子窗体的方法获取子窗体的高度，来设置iframe的高度
        //在父窗体获得的高度会有缓存，不能及时更新iframe的高度
        iframe.height = iframe.contentWindow.getDocumentHeight();
    }


});


/**
 * 导航菜单点击事件
 * @param 路径
 * @param 节点 最大三层节点
 */
function initNavMenuClickHandler(obj, src, jd) {

    var if_title = $('#iframeTilte');
    var if_url = $('#breadcrumb');
    var iframe = $('#frameContext');

    var urlContent = '<li> ' +
        ' <a href="#" tittle="首页"><span class="entypo-home"></span></a>' +
        '</li>' +
        '<li>' +
        '<i class="fa fa-lg fa-angle-right"></i>' +
        '</li>';
    if (jd == 3) {

        //绑定title
        if_title.html($(obj).find('span').html());

        //绑定url
        urlContent += '<li>' +
            '<a href="#">' + $(obj).parent('li').parent('ul').parent('li').prev('li').find('span').html() + '</a>' +
            '</li>';

        urlContent += '<li>' +
            '<i class="fa fa-lg fa-angle-right"></i>' +
            '</li>' +
            '<li>' +
            '<a href="#">' + $(obj).parent('li').parent('ul').prev('a').find('span').html() + '</a>' +
            '</li>';
        urlContent += '<li>' +
            '<i class="fa fa-lg fa-angle-right"></i>' +
            '</li>' +
            '<li>' +
            '<a href="#">' + $(obj).find('span').html() + '</a>' +
            '</li>';
        if_url.html(urlContent);
    } else if (jd == 2) {

        //绑定title
        if_title.html($(obj).find('span').html());

        urlContent += '<li>' +
            '<a href="#">' + $(obj).parent('li').prev('li').find('span').html() + '</a>' +
            '</li>';
        urlContent += '<li>' +
            '<i class="fa fa-lg fa-angle-right"></i>' +
            '</li>' +
            '<li>' +
            '<a href="#">' + $(obj).find('span').html() + '</a>' +
            '</li>';
        if_url.html(urlContent);
    }

    //清除iframe缓存
    clearIframe('frameContext');

    iframe.attr('src', src);

    //设置iframe的高度
    //setIframeHeight('frameContext');
}

/**
 * 根据iframe内部内容修改iframe的高度
 * @param id
 */
function setIframeHeight(id) {
    var iframe = document.getElementById(id);


    var height = $("#" + id).contents().find("body").height();

    iframe.height = height;


//	$('body').height(height + 250);
//	
//	
//	alert($('#'+id).height() + "  " + $('body').height() + "  "+ $('#skin-select').height());


    try {
        if (iframe.attachEvent) {
            iframe.attachEvent("onload", function () {
                iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
            });
            iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
            return;
        } else {
            iframe.onload = function () {
                iframe.height = iframe.contentDocument.body.scrollHeight;
            };

            iframe.height = iframe.contentDocument.body.scrollHeight;
            return;
        }
    } catch (e) {

    }
}


/**
 * 获取天气信息显示
 */
function findWeather() {
    var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
    $.getScript(cityUrl, function (script, textStatus, jqXHR) {
        var citytq = remote_ip_info.city;// 获取城市
        var url = "http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city=" + citytq + "&day=0&dfc=3";
        $.ajax({
            url: url,
            dataType: "script",
            scriptCharset: "gbk",
            success: function (data) {
                var _w = window.SWther.w[citytq][0];
                var _f = _w.f1 + "_0.png";
                if (new Date().getHours() > 17) {
                    _f = _w.f2 + "_1.png";
                }
                var img = "<img width='16px' height='16px' src='http://i2.sinaimg.cn/dy/main/weather/weatherplugin/wthIco/20_20/" + _f
                    + "' />";
                var tq = citytq + " " + img + " " + _w.s1 + " " + _w.t1 + "℃～" + _w.t2 + "℃ " + _w.d1 + _w.p1 + "级";

                $('#nt-title').html(tq);
            }
        });
    });
}


/**
 * 加载菜单样式
 */
function loadMenuTree() {
    head.js("/thridPartyService/core/iframe/assets/js/tip/jquery.tooltipster.js", function () {

        $('.tooltip-tip-x').tooltipster({
            position: 'right'

        });

        $('.tooltip-tip').tooltipster({
            position: 'right',
            animation: 'slide',
            theme: '.tooltipster-shadow',
            delay: 1,
            offsetX: '-12px',
            onlyOne: true

        });
        $('.tooltip-tip2').tooltipster({
            position: 'right',
            animation: 'slide',
            offsetX: '-12px',
            theme: '.tooltipster-shadow',
            onlyOne: true

        });
        $('.tooltip-top').tooltipster({
            position: 'top'
        });
        $('.tooltip-right').tooltipster({
            position: 'right'
        });
        $('.tooltip-left').tooltipster({
            position: 'left'
        });
        $('.tooltip-bottom').tooltipster({
            position: 'bottom'
        });
        $('.tooltip-reload').tooltipster({
            position: 'right',
            theme: '.tooltipster-white',
            animation: 'fade'
        });
        $('.tooltip-fullscreen').tooltipster({
            position: 'left',
            theme: '.tooltipster-white',
            animation: 'fade'
        });
        //For icon tooltip
    });
}
